package com.esri.core.internal.tasks.e.a;

import com.amap.api.services.core.AMapException;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.geometry.WkbGeometryType;
import java.util.List;
import java.util.Locale;
import java.util.Set;

/* loaded from: classes.dex */
public class g {
    public static String a = "CRS:84";
    public static String b = "EPSG:4326";
    public static String c = "EPSG:102100";
    public static String d = "EPSG:3857";
    private static int[][] g = {new int[]{AMapException.CODE_AMAP_SHARE_FAILURE, 4999}, new int[]{2044, 2045}, new int[]{2081, 2083}, new int[]{2085, 2086}, new int[]{2093, 2093}, new int[]{2096, 2098}, new int[]{2105, 2132}, new int[]{2169, 2170}, new int[]{2176, 2180}, new int[]{2193, 2193}, new int[]{AMapException.CODE_AMAP_CLIENT_UPLOADAUTO_STARTED_ERROR, AMapException.CODE_AMAP_CLIENT_UPLOADAUTO_STARTED_ERROR}, new int[]{2206, 2212}, new int[]{2319, 2319}, new int[]{2320, 2462}, new int[]{2523, 2549}, new int[]{2551, 2735}, new int[]{2738, 2758}, new int[]{2935, 2941}, new int[]{2953, 2953}, new int[]{WkbGeometryType.wkbMultiPolygonZM, 3030}, new int[]{3034, 3035}, new int[]{3058, 3059}, new int[]{3068, 3068}, new int[]{3114, 3118}, new int[]{3126, 3138}, new int[]{3300, 3301}, new int[]{3328, 3335}, new int[]{3346, 3346}, new int[]{3350, 3352}, new int[]{3366, 3366}, new int[]{3416, 3416}, new int[]{20004, 20032}, new int[]{20064, 20092}, new int[]{21413, 21423}, new int[]{21473, 21483}, new int[]{21896, 21899}, new int[]{22171, 22177}, new int[]{22181, 22187}, new int[]{22191, 22197}, new int[]{25884, 25884}, new int[]{27205, 27232}, new int[]{27391, 27398}, new int[]{27492, 27492}, new int[]{28402, 28432}, new int[]{28462, 28492}, new int[]{30161, 30179}, new int[]{30800, 30800}, new int[]{31251, 31259}, new int[]{31275, 31279}, new int[]{31281, 31290}, new int[]{31466, 31700}, new int[]{3038, 3051}};
    private static int[] h = {84, 4326, 83, 4269, 27, 4267};
    Envelope e;
    String f;

    public Envelope a() {
        return this.e;
    }

    public void a(Envelope envelope) {
        this.e = envelope;
    }

    public String b() {
        return this.f;
    }

    public void a(String str) {
        this.f = str;
    }

    public static int b(String str) {
        if (str != null) {
            String trim = str.trim();
            if (trim.toUpperCase(Locale.ENGLISH).startsWith("EPSG:")) {
                try {
                    int parseInt = Integer.parseInt(trim.substring(5));
                    if (parseInt == 900913) {
                        return 3857;
                    }
                    return parseInt;
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            } else if (trim.toUpperCase(Locale.ENGLISH).startsWith("CRS:")) {
                try {
                    int intValue = Integer.valueOf(trim.substring(4)).intValue();
                    int i = 0;
                    while (true) {
                        int[] iArr = h;
                        if (i >= iArr.length / 2) {
                            break;
                        }
                        int i2 = i * 2;
                        if (intValue == iArr[i2]) {
                            return iArr[i2 + 1];
                        }
                        i++;
                    }
                } catch (NumberFormatException e2) {
                    e2.printStackTrace();
                }
            }
        }
        return -1;
    }

    public static String a(SpatialReference spatialReference, List<String> list) {
        if (spatialReference == null) {
            return null;
        }
        if (list == null) {
            return "EPSG:" + spatialReference.getID();
        } else if (spatialReference.getLatestID() == 3857) {
            return list.contains("EPSG:3857") ? "EPSG:3857" : list.contains("EPSG:3785") ? "EPSG:3785" : list.contains("EPSG:102100") ? "EPSG:102100" : "EPSG:102113";
        } else if (spatialReference.getID() == 4326) {
            return list.contains("CRS:84") ? "CRS:84" : "EPSG:4326";
        } else if (spatialReference.getID() == 4269) {
            return list.contains("CRS:83") ? "CRS:83" : "EPSG:4269";
        } else if (spatialReference.getID() == 4267) {
            return list.contains("CRS:27") ? "CRS:27" : "EPSG:4267";
        } else {
            return "EPSG:" + spatialReference.getID();
        }
    }

    public static boolean a(String str, String str2) {
        if (f.d.equals(str) && str2 != null && str2.length() > 4) {
            String trim = str2.trim();
            if (!trim.toUpperCase(Locale.ENGLISH).startsWith("CRS:") && trim.toUpperCase(Locale.ENGLISH).startsWith("EPSG:")) {
                try {
                    int intValue = Integer.valueOf(trim.toUpperCase(Locale.ENGLISH).substring(5)).intValue();
                    int i = 0;
                    while (true) {
                        int[][] iArr = g;
                        if (i >= iArr.length) {
                            break;
                        } else if (intValue >= iArr[i][0] && intValue <= iArr[i][1]) {
                            return true;
                        } else {
                            i++;
                        }
                    }
                } catch (NumberFormatException unused) {
                }
            }
        }
        return false;
    }

    public static int[] a(Set<String> set) {
        if (set == null || set.size() <= 0) {
            return null;
        }
        int[] iArr = new int[set.size()];
        int i = 0;
        for (String str : set) {
            iArr[i] = b(str);
            i++;
        }
        return iArr;
    }

    public static Envelope b(Envelope envelope) {
        if (envelope == null) {
            return null;
        }
        Envelope envelope2 = new Envelope();
        envelope2.setXMax(envelope.getYMax());
        envelope2.setYMax(envelope.getXMax());
        envelope2.setXMin(envelope.getYMin());
        envelope2.setYMin(envelope.getXMin());
        return envelope2;
    }
}
